import os
from datetime import datetime
from fastapi import APIRouter, Depends, File, Form, Query, Request, UploadFile ,Body
from sqlalchemy.ext.asyncio import AsyncSession
from typing import Literal, Optional, Union ,List
from pydantic_validation_decorator import ValidateFields
from config.get_db import get_db
from config.enums import BusinessType
from config.env import UploadConfig
from module_admin.annotation.log_annotation import Log
from module_admin.aspect.data_scope import GetDataScope
from utils.common_util import bytes2file_response
from utils.log_util import logger
from utils.page_util import PageResponseModel
from utils.pwd_util import PwdUtil
from utils.response_util import ResponseUtil
from utils.upload_util import UploadUtil
from module_admin.service.login_service import LoginService
from module_admin.service.picture_service import PictureService
from module_admin.entity.vo.picture_parse_vo import PictureParsePageModel, PictureParseModel,PictureModel,BatchInsertModel,PictureDifferModel
from module_admin.entity.vo.user_vo import (
    AddUserModel,
    CrudUserRoleModel,
    CurrentUserModel,
    DeleteUserModel,
    EditUserModel,
    ResetPasswordModel,
    ResetUserModel,
    UserDetailModel,
    UserInfoModel,
    UserModel,
    UserPageQueryModel,
    UserProfileModel,
    UserRoleQueryModel,
    UserRoleResponseModel,
)

pictureController = APIRouter(prefix='/system/picture', dependencies=[Depends(LoginService.get_current_user)])



@pictureController.post('/importData')
@Log(title='ocr识别', business_type=BusinessType.IMPORT)
async def batch_import_system_picture(
    request: Request,
    file: UploadFile = File(...),
    query_db: AsyncSession = Depends(get_db),
    current_user: CurrentUserModel = Depends(LoginService.get_current_user)
):
    import_result = await PictureService.import_picture_services(
        request, query_db, file, current_user
    )
    logger.info(import_result.result)

    return ResponseUtil.success(msg=import_result.result)

@pictureController.post('/llmCheck')
@Log(title='图片AI转文字识别', business_type=BusinessType.OTHER)
async def system_picture_llmCheck(
    request: Request,
    picture_model: PictureModel,
    query_db: AsyncSession = Depends(get_db),
    current_user: CurrentUserModel = Depends(LoginService.get_current_user)
):
    check_result = await PictureService.system_picture_llmCheck(
        request, query_db, picture_model, current_user
    )
    logger.info(check_result)

    return ResponseUtil.success(msg=check_result.result)


@pictureController.post('/batchInsert')
@Log(title='批量插入', business_type=BusinessType.INSERT)
async def batch_insert_system_picture(
    request: Request,
    add_model: BatchInsertModel,
    query_db: AsyncSession = Depends(get_db),
    current_user: CurrentUserModel = Depends(LoginService.get_current_user)
):  
    await PictureService.batch_insert_system_picture(
        request, query_db, add_model, current_user
    )

    return ResponseUtil.success(msg="保存成功")


@pictureController.post('/differ')
@Log(title='图片管理', business_type=BusinessType.OTHER)
async def differ(
    request: Request,
    picture_model: PictureDifferModel,
    query_db: AsyncSession = Depends(get_db),
    current_user: CurrentUserModel = Depends(LoginService.get_current_user)
):
    check_result = await PictureService.differ(
        request, query_db, picture_model, current_user
    )
    logger.info(check_result)

    return ResponseUtil.success(msg=check_result.result)